/*
               File: Documentos
        Description: Documentos SUNAT
             Author: GeneXus Java Generator version 8_0_9-040
       Generated on: 18 de Junio de 2010 16:7:59.95
       Program type: Callable routine
          Main DBMS: sqlserver
*/
import com.genexus.*;
import com.genexus.ui.*;
import com.genexus.db.*;
import com.genexus.distributed.*;
import com.genexus.uifactory.*;
import java.sql.*;

/* Client and Server side code */
public final class tdocumentos extends GXTransaction
{
   public tdocumentos( int remoteHandle )
   {
      super( remoteHandle , new ModelContext( tdocumentos.class ), "" );
   }

   public tdocumentos( int remoteHandle ,
                       ModelContext context )
   {
      super( remoteHandle , context, "" );
   }

   public void init_no_key0o24( )
   {
      A356DESDOC = "" ;
   }

   public void init_all0o24( )
   {
      A355CODDOC = 0 ;
      K355CODDOC = A355CODDOC ;
      geteqAfterKey = (byte)(1) ;
      clear( ) ;
      init_no_key0o24( ) ;
   }

   public void samod_set_ins( )
   {
   }

   public void reset_caption_0o0( )
   {
   }

   /* Client side code */
   public void sa_startup( )
   {
      sa_startup_srv( ) ;
      disable_std_buttons( ) ;
      enable_disable( ) ;
   }

   protected String getObjectName( )
   {
      return "Documentos" ;
   }

   protected String getFrmTitle( )
   {
      return "Documentos SUNAT" ;
   }

   protected GXMenuBar getMenuBar( )
   {
      return new GXMenuBarDefaultTRN(this) ;
   }

   protected int getFrmTop( )
   {
      return 0 ;
   }

   protected int getFrmLeft( )
   {
      return 0 ;
   }

   protected int getFrmWidth( )
   {
      return 731 ;
   }

   protected int getFrmHeight( )
   {
      return 182 ;
   }

   protected String getHelpId( )
   {
      return "HLP_TDocumentos.htm";
   }

   protected int getFrmBackground( )
   {
      return UIFactory.getColor(15) ;
   }

   protected int getFrmForeground( )
   {
      return UIFactory.getColor(6) ;
   }

   protected boolean isMainProgram( )
   {
      return false;
   }

   protected boolean isModal( )
   {
      return false;
   }

   protected boolean hasDBAccess( )
   {
      return true ;
   }

   protected int getRefreshTimeout( )
   {
      return 0 ;
   }

   public boolean getRefreshTimeoutAlways( )
   {
      return true ;
   }

   protected boolean getPaintAfterStart( )
   {
      return true ;
   }

   protected int getBorderStyle( )
   {
      return 2 ;
   }

   protected boolean getMaxButton( )
   {
      return true ;
   }

   protected boolean getMinButton( )
   {
      return true ;
   }

   protected boolean getCtrlBox( )
   {
      return true ;
   }

   protected boolean getShowInTaskbar( )
   {
      return true ;
   }

   protected String getFormIcon( )
   {
      return "" ;
   }

   protected boolean getAutocenter( )
   {
      return true ;
   }

   public void execute( )
   {
      execute_int();
   }

   private void execute_int( )
   {
      start();
   }

   protected void screen( )
   {
      GXPanel1 = new GXPanel(this, 0 , 0 , 731 , 182 );
      this.setIBackground(UIFactory.getColor(15));
      this.setIForeground(UIFactory.getColor(6));
      GXPanel1.refreshFrame();
      edtCODDOCSUN = new GUIObjectByte ( new GXEdit(2, "Z9", UIFactory.getFont( "Courier New", 0, 9),245, 48, 24, 21, GXPanel1, false, ILabelConstants.BORDER_3D, GXTypeConstants.NUMERIC, false, true) , GXPanel1 , 245 , 48 , 24 , 21 , UIFactory.getColor(5) , UIFactory.getColor(8) , UIFactory.getFont( "Courier New", 0, 9) , true , "A355CODDOC" );
      ((GXEdit) edtCODDOCSUN.getGXComponent()).setAlignment(ILabelConstants.RIGHT);
      edtCODDOCSUN.addFocusListener(this);
      edtCODDOCSUN.getGXComponent().setHelpId("HLP_TDocumentos.htm");
      edtDESDOCSUN = new GUIObjectString ( new GXEdit(50, "@!", UIFactory.getFont( "Courier New", 0, 9),245, 72, 360, 21, GXPanel1, false, ILabelConstants.BORDER_3D, GXTypeConstants.CHAR, false, true) , GXPanel1 , 245 , 72 , 360 , 21 , UIFactory.getColor(5) , UIFactory.getColor(8) , UIFactory.getFont( "Courier New", 0, 9) , true , "A356DESDOC" );
      ((GXEdit) edtDESDOCSUN.getGXComponent()).setAlignment(ILabelConstants.LEFT);
      edtDESDOCSUN.addFocusListener(this);
      edtDESDOCSUN.getGXComponent().setHelpId("HLP_TDocumentos.htm");
      bttBtn_first = UIFactory.getGXButton( GXPanel1 , "|<" ,  8 ,  2 ,  26 ,  24 , UIFactory.getFont( "MS Shell Dlg", 0, 8) );
      bttBtn_first.setTooltip("|<");
      bttBtn_first.addActionListener(this);
      bttBtn_first.setFiresEvents(false);
      bttBtn_previous = UIFactory.getGXButton( GXPanel1 , "<" ,  34 ,  2 ,  26 ,  24 , UIFactory.getFont( "MS Shell Dlg", 0, 8) );
      bttBtn_previous.setTooltip("<");
      bttBtn_previous.addActionListener(this);
      bttBtn_previous.setFiresEvents(false);
      bttBtn_next = UIFactory.getGXButton( GXPanel1 , ">" ,  60 ,  2 ,  26 ,  24 , UIFactory.getFont( "MS Shell Dlg", 0, 8) );
      bttBtn_next.setTooltip(">");
      bttBtn_next.addActionListener(this);
      bttBtn_next.setFiresEvents(false);
      bttBtn_last = UIFactory.getGXButton( GXPanel1 , ">|" ,  86 ,  2 ,  26 ,  24 , UIFactory.getFont( "MS Shell Dlg", 0, 8) );
      bttBtn_last.setTooltip(">|");
      bttBtn_last.addActionListener(this);
      bttBtn_last.setFiresEvents(false);
      bttBtn_select = UIFactory.getGXButton( GXPanel1 , "Seleccionar" ,  115 ,  2 ,  89 ,  24 , UIFactory.getFont( "MS Shell Dlg", 0, 8) );
      bttBtn_select.setTooltip("Seleccionar");
      bttBtn_select.addActionListener(this);
      bttBtn_select.setFiresEvents(false);
      bttBtn_enter = UIFactory.getGXButton( GXPanel1 , "Confirmar" ,  623 ,  48 ,  89 ,  23 , UIFactory.getFont( "MS Shell Dlg", 0, 8) );
      bttBtn_enter.setTooltip("Confirmar");
      bttBtn_enter.addActionListener(this);
      bttBtn_cancel = UIFactory.getGXButton( GXPanel1 , "Cerrar" ,  623 ,  76 ,  89 ,  23 , UIFactory.getFont( "MS Shell Dlg", 0, 8) );
      bttBtn_cancel.setTooltip("Cerrar");
      bttBtn_cancel.addActionListener(this);
      bttBtn_cancel.setFiresEvents(false);
      bttBtn_delete = UIFactory.getGXButton( GXPanel1 , "Eliminar" ,  623 ,  104 ,  89 ,  23 , UIFactory.getFont( "MS Shell Dlg", 0, 8) );
      bttBtn_delete.setTooltip("Eliminar");
      bttBtn_delete.addActionListener(this);
      bttBtn_help = UIFactory.getGXButton( GXPanel1 , "Ayuda" ,  623 ,  142 ,  89 ,  23 , UIFactory.getFont( "MS Shell Dlg", 0, 8) );
      bttBtn_help.setTooltip("Ayuda");
      bttBtn_help.addActionListener(this);
      lbllbl12 = UIFactory.getLabel(GXPanel1, "Codigo de Documento SUNAT", ILabelConstants.LEFT, Integer.MAX_VALUE, UIFactory.getColor(8), UIFactory.getFont( "MS Sans Serif", IFontConstants.BOLD, 8), false, ILabelConstants.BORDER_NONE , 21 , 48 , 172 , 13 );
      lbllbl14 = UIFactory.getLabel(GXPanel1, "Descripcion de Documento SUNAT", ILabelConstants.LEFT, Integer.MAX_VALUE, UIFactory.getColor(8), UIFactory.getFont( "MS Sans Serif", IFontConstants.BOLD, 8), false, ILabelConstants.BORDER_NONE , 21 , 72 , 200 , 13 );
      focusManager.setControlList(new IFocusableControl[] {
                edtCODDOCSUN ,
                edtDESDOCSUN ,
                bttBtn_enter ,
                bttBtn_cancel ,
                bttBtn_delete ,
                bttBtn_help ,
                bttBtn_first ,
                bttBtn_previous ,
                bttBtn_next ,
                bttBtn_last ,
                bttBtn_select
      });
   }

   protected void setFocusFirst( )
   {
      setFocus(edtCODDOCSUN, true);
   }

   public void reloadDynamicLists( int id )
   {
   }

   public void clear( )
   {
      init_no_key0o24( ) ;
   }

   public void disable_std_buttons( )
   {
   }

   public void set_caption( )
   {
      if ( ( IsConfirmed == 1 ) && ( AnyError == 0 ) )
      {
         if ( ( GXutil.strcmp(Gx_mode, "DLT") == 0 ) )
         {
            context.msgStatus( localUtil.getMessages().getMessage("confdelete") );
         }
         else
         {
            context.msgStatus( localUtil.getMessages().getMessage("mustconfirm") );
         }
         bttBtn_enter.setCaption( localUtil.getMessages().getMessage("captionconfirm") );
         bttBtn_enter.setTooltip( localUtil.getMessages().getMessage("captionconfirm") );
      }
      else if ( ( GXutil.strcmp(Gx_mode, "INS") == 0 ) )
      {
         bttBtn_enter.setCaption( localUtil.getMessages().getMessage("captionadd") );
         bttBtn_enter.setTooltip( localUtil.getMessages().getMessage("captionadd") );
      }
      else if ( ( GXutil.strcmp(Gx_mode, "UPD") == 0 ) )
      {
         bttBtn_enter.setCaption( localUtil.getMessages().getMessage("captionupdate") );
         bttBtn_enter.setTooltip( localUtil.getMessages().getMessage("captionupdate") );
      }
      else if ( ( GXutil.strcmp(Gx_mode, "DLT") == 0 ) )
      {
         bttBtn_enter.setCaption( localUtil.getMessages().getMessage("captiondelete") );
         bttBtn_enter.setTooltip( localUtil.getMessages().getMessage("captiondelete") );
      }
      else
      {
      }
   }

   public void after_trn( )
   {
      if ( ( trnEnded == 1 ) )
      {
         trnEnded = 0 ;
         if (!cleanedUp) {
            sanomod( ) ;
            if ( (GXutil.strcmp(Gx_mode, "INS")==0) )
            {
               /* Clear variables for new insertion. */
               init_all0o24( ) ;
               sanomod( ) ;
               samod( ) ;
            }
         }
      }
   }

   protected boolean hasStatusBar( )
   {
      return true;
   }

   public void refreshArray( String array )
   {
   }

   protected void GXEnter( )
   {
      btn_enter( ) ;
      if (!cleanedUp) {
         VariablesToControls();
         set_caption( );
      }
   }

   protected void GXStart( )
   {
      sa_startup( ) ;
      VariablesToControls();
      /* Execute Start event if defined. */
   }

   protected void actionEventDispatch( Object eventSource )
   {
      lastAnyError = AnyError ;
      AnyError = 0;
      if ( bttBtn_cancel.isEventSource(eventSource) ) {
         if (canCleanup())
            cleanup();

         return;
      }
      if ( bttBtn_help.isEventSource(eventSource) ) {
         showHelp();
         return;
      }
      if ( bttBtn_first.isEventSource(eventSource) ) {
         if ( ( lastAnyError != 0 ) )
         {
            return;
         }
         btn_first( ) ;
         if (!cleanedUp) {
            VariablesToControls();
            set_caption( );
         }
         return;
      }
      if ( bttBtn_previous.isEventSource(eventSource) ) {
         if ( ( lastAnyError != 0 ) )
         {
            return;
         }
         btn_previous( ) ;
         if (!cleanedUp) {
            VariablesToControls();
            set_caption( );
         }
         return;
      }
      if ( bttBtn_next.isEventSource(eventSource) ) {
         if ( ( lastAnyError != 0 ) )
         {
            return;
         }
         btn_next( ) ;
         if (!cleanedUp) {
            VariablesToControls();
            set_caption( );
         }
         return;
      }
      if ( bttBtn_last.isEventSource(eventSource) ) {
         if ( ( lastAnyError != 0 ) )
         {
            return;
         }
         btn_last( ) ;
         if (!cleanedUp) {
            VariablesToControls();
            set_caption( );
         }
         return;
      }
      if ( bttBtn_select.isEventSource(eventSource) ) {
         if ( ( lastAnyError != 0 ) )
         {
            return;
         }
         btn_select( ) ;
         if (!cleanedUp) {
            VariablesToControls();
            set_caption( );
         }
         return;
      }
      if ( bttBtn_enter.isEventSource(eventSource) ) {
         if ( ( lastAnyError != 0 ) )
         {
            return;
         }
         btn_enter( ) ;
         if (!cleanedUp) {
            VariablesToControls();
            set_caption( );
         }
         return;
      }
      if ( bttBtn_delete.isEventSource(eventSource) ) {
         if ( ( lastAnyError != 0 ) )
         {
            return;
         }
         btn_delete( ) ;
         if (!cleanedUp) {
            VariablesToControls();
            set_caption( );
         }
         return;
      }
   }

   protected void setCurrentGXCursor( Object eventSource )
   {
      if ( edtCODDOCSUN.isEventSource(eventSource) ) {
         setGXCursor( edtCODDOCSUN.getGXCursor() );
         return;
      }
      if ( edtDESDOCSUN.isEventSource(eventSource) ) {
         setGXCursor( edtDESDOCSUN.getGXCursor() );
         return;
      }
   }

   protected void gotFocusEventDispatch( Object eventSource )
   {
   }

   protected void focusEventDispatch( Object eventSource )
   {
      AnyError = 0 ;
      if ( edtCODDOCSUN.isEventSource(eventSource) ) {
         valid_coddocsun ();
         return;
      }
   }

   protected void updateAttributes( Object eventSource )
   {
      if ( edtCODDOCSUN.isEventSource(eventSource) ) {
         A355CODDOC = edtCODDOCSUN.getValue() ;
         return;
      }
      if ( edtDESDOCSUN.isEventSource(eventSource) ) {
         A356DESDOC = edtDESDOCSUN.getValue() ;
         return;
      }
   }

   protected void itemEventDispatch( Object eventSource )
   {
   }

   public void mouseEventDispatch( Object eventSource ,
                                   int modifier )
   {
   }

   public boolean keyEventDispatch( Object eventSource ,
                                    int keyCode )
   {
      if (triggerEventEnter(eventSource, keyCode)) {
         AnyError = 0;
         btn_enter( ) ;
         if (!cleanedUp) {
            VariablesToControls();
            set_caption( );
         }
         return true ;
      }
      if (keyCode == getContext().getClientPreferences().getKEY_PROMPT()) {
         return keyPromptHandler(eventSource);
      }
      return false;
   }

   public boolean isKeyControl( Object eventSource )
   {
      if ( ( edtCODDOCSUN.isEventSource(eventSource) ) && ( ( A355CODDOC != edtCODDOCSUN.getValue() ) ) )
      {
         return true;
      }
      return false;
   }

   public boolean isBodyControl( Object eventSource )
   {
      if ( ( edtDESDOCSUN.isEventSource(eventSource) ) && ( ( GXutil.strcmp(A356DESDOC, edtDESDOCSUN.getValue()) != 0 ) ) )
      {
         return true;
      }
      return false;
   }

   public boolean menuActionPerformed( String action )
   {
      return false;
   }

   protected void resetCaption( )
   {
      reset_caption_0o0( ) ;
   }

   protected void setAddCaption( )
   {
      bttBtn_enter.setCaption( localUtil.getMessages().getMessage("captionadd") );
      bttBtn_enter.setTooltip( localUtil.getMessages().getMessage("captionadd") );
   }

   public IGXButton getCancelButton( )
   {
      return bttBtn_cancel ;
   }

   public IGXButton getConfirmButton( )
   {
      return bttBtn_enter ;
   }

   public IGXButton getDeleteButton( )
   {
      return bttBtn_delete ;
   }

   protected boolean keyPromptHandler( Object eventSource )
   {
      return false;
   }

   protected void VariablesToControls( )
   {
      edtCODDOCSUN.setValue( A355CODDOC );
      edtDESDOCSUN.setValue( A356DESDOC );
   }

   protected void ControlsToVariables( )
   {
      A355CODDOC = edtCODDOCSUN.getValue() ;
      A356DESDOC = edtDESDOCSUN.getValue() ;
   }

   protected void eventNoLevelContext( )
   {
      ControlsToVariables();
   }

   protected void eventLevelContext( )
   {
      ControlsToVariables();
   }

   protected void eventLevelResetContext( )
   {
   }

   protected void reloadGridRow( )
   {
   }

   public void valid_coddocsun( )
   {
      if ( ( A355CODDOC != K355CODDOC ) || ( geteqAfterKey == 1 ) )
      {
         if ( ( AnyError == 0 ) )
         {
            K355CODDOC = A355CODDOC ;
            geteq_nomod( ) ;
            VariablesToControls();
         }
         if ( ( AnyError == 0 ) )
         {
            geteqAfterKey = 0 ;
         }
         else
         {
            geteqAfterKey = (byte)(1) ;
         }
      }
      IsConfirmed = 0 ;
      set_caption( ) ;
   }

   /* Server side code */
   /* Aggregate/select formulas */
   /* Vertical formulas */
   public void sa_startup_srv( )
   {
      if ( ( AnyError == 0 ) )
      {
         sanomod( ) ;
         Gx_mode = "INS" ;
         samod( ) ;
         if ( ( GXutil.strcmp(Gx_mode, "INS") == 0 ) )
         {
         }
      }
      set_caption( ) ;
      PreviousCaption = bttBtn_enter.getCaption() ;
   }

   public void zm0o24( int GX_JID )
   {
      if ( ( GX_JID == 1 ) || ( GX_JID == 0 ) )
      {
         if ( ( GXutil.strcmp(Gx_mode, "INS") != 0 ) )
         {
            Z356DESDOC = T00243_A356DESDOC[0] ;
         }
         else
         {
            Z356DESDOC = A356DESDOC ;
         }
      }
   }

   public void sanomod( )
   {
   }

   public void samod( )
   {
   }

   public void ld0o24( )
   {
   }

   public void checket_0o24( )
   {
      Gx_BScreen = (byte)(1) ;
      samod( ) ;
      Gx_BScreen = 0 ;
   }

   public void close_checket_0o24( )
   {
   }

   public void enable_disable( )
   {
   }

   public void getkey_0o24( )
   {
      /* Using cursor T00244 */
      pr_default.execute(2, new Object[] {new Byte(A355CODDOC)});
      if ( (pr_default.getStatus(2) != 101) )
      {
         RcdFound24 = (short)(1) ;
      }
      else
      {
         RcdFound24 = 0 ;
      }
      pr_default.close(2);
   }

   public void geteq( )
   {
      /* Using cursor T00243 */
      pr_default.execute(1, new Object[] {new Byte(A355CODDOC)});
      if ( (pr_default.getStatus(1) != 101) )
      {
         zm0o24( 1) ;
         RcdFound24 = (short)(1) ;
         A355CODDOC = T00243_A355CODDOC[0] ;
         A356DESDOC = T00243_A356DESDOC[0] ;
         Z355CODDOC = A355CODDOC ;
         sMode24 = Gx_mode ;
         Gx_mode = "DSP" ;
         samod( ) ;
         ld0o24( ) ;
         Gx_mode = sMode24 ;
      }
      else
      {
         RcdFound24 = 0 ;
         init_no_key0o24( ) ;
         sMode24 = Gx_mode ;
         Gx_mode = "DSP" ;
         samod( ) ;
         Gx_mode = sMode24 ;
      }
      K355CODDOC = A355CODDOC ;
      pr_default.close(1);
   }

   public void geteq_nomod( )
   {
      getkey_0o24( ) ;
      if ( ( RcdFound24 == 0 ) )
      {
         Gx_mode = "INS" ;
      }
      else
      {
         Gx_mode = "UPD" ;
      }
      geteq( ) ;
   }

   public void move_next( )
   {
      RcdFound24 = 0 ;
      /* Using cursor T00245 */
      pr_default.execute(3, new Object[] {new Byte(A355CODDOC)});
      if ( (pr_default.getStatus(3) != 101) )
      {
         while ( (pr_default.getStatus(3) != 101) && ( ( T00245_A355CODDOC[0] < A355CODDOC ) ) )
         {
            pr_default.readNext(3);
         }
         if ( (pr_default.getStatus(3) != 101) && ( ( T00245_A355CODDOC[0] > A355CODDOC ) ) )
         {
            A355CODDOC = T00245_A355CODDOC[0] ;
            RcdFound24 = (short)(1) ;
         }
      }
      pr_default.close(3);
   }

   public void move_previous( )
   {
      RcdFound24 = 0 ;
      /* Using cursor T00246 */
      pr_default.execute(4, new Object[] {new Byte(A355CODDOC)});
      if ( (pr_default.getStatus(4) != 101) )
      {
         while ( (pr_default.getStatus(4) != 101) && ( ( T00246_A355CODDOC[0] > A355CODDOC ) ) )
         {
            pr_default.readNext(4);
         }
         if ( (pr_default.getStatus(4) != 101) && ( ( T00246_A355CODDOC[0] < A355CODDOC ) ) )
         {
            A355CODDOC = T00246_A355CODDOC[0] ;
            RcdFound24 = (short)(1) ;
         }
      }
      pr_default.close(4);
   }

   public void btn_enter( )
   {
      nKeyPressed = (byte)(1) ;
      getkey_0o24( ) ;
      if ( ( RcdFound24 == 1 ) )
      {
         if ( ( GXutil.strcmp(Gx_mode, "INS") == 0 ) )
         {
            pushError( localUtil.getMessages().getMessage("noupdate") );
            AnyError = (short)(1) ;
            setNextFocus( edtCODDOCSUN );
         }
         else if ( ( A355CODDOC != Z355CODDOC ) )
         {
            A355CODDOC = Z355CODDOC ;
            edtCODDOCSUN.setValue(A355CODDOC);
            pushError( localUtil.getMessages().getMessage("getbeforeupd") );
            AnyError = (short)(1) ;
            setNextFocus( edtCODDOCSUN );
         }
         else
         {
            Gx_mode = "UPD" ;
            /* Update record */
            update_0o24( ) ;
            setNextFocus( edtCODDOCSUN );
         }
      }
      else
      {
         if ( ( A355CODDOC != Z355CODDOC ) )
         {
            Gx_mode = "INS" ;
            /* Insert record */
            insert_0o24( ) ;
            setNextFocus( edtCODDOCSUN );
         }
         else
         {
            if ( ( GXutil.strcmp(Gx_mode, "UPD") == 0 ) )
            {
               pushError( localUtil.getMessages().getMessage("recdeleted") );
               AnyError = (short)(1) ;
               setNextFocus( edtCODDOCSUN );
            }
            else
            {
               Gx_mode = "INS" ;
               /* Insert record */
               insert_0o24( ) ;
               setNextFocus( edtCODDOCSUN );
            }
         }
      }
      handleErrors();
      after_trn( ) ;
      if ( ( sanomodError == 0 ) )
      {
         handleErrors();
      }
      setFocusNext();
      AnyError = 0 ;
      if	(loopOnce) cleanup();
   }

   public void btn_delete( )
   {
      if ( ( A355CODDOC != Z355CODDOC ) )
      {
         A355CODDOC = Z355CODDOC ;
         edtCODDOCSUN.setValue(A355CODDOC);
         pushError( localUtil.getMessages().getMessage("getbeforedlt") );
         AnyError = (short)(1) ;
         setNextFocus( edtCODDOCSUN );
      }
      else
      {
         GXutil.confirm( me(), localUtil.getMessages().getMessage("deleinfo") , true );
         if ( GXutil.Confirmed )
         {
            delete( ) ;
            handleErrors();
            after_trn( ) ;
            setNextFocus( edtCODDOCSUN );
         }
      }
      if ( ( AnyError != 0 ) )
      {
         Gx_mode = "UPD" ;
      }
      geteq( ) ;
      if ( ( sanomodError == 0 ) )
      {
         handleErrors();
      }
      setFocusNext();
   }

   public void btn_get( )
   {
      nKeyPressed = (byte)(2) ;
      IsConfirmed = 0 ;
      geteq_nomod( ) ;
      if ( ( RcdFound24 == 0 ) )
      {
         pushError( localUtil.getMessages().getMessage("keynfound") );
         AnyError = (short)(1) ;
         keepFocus();
      }
      else
      {
         setNextFocus( edtDESDOCSUN );
      }
      if ( ( sanomodError == 0 ) )
      {
         handleErrors();
      }
      setFocusNext();
   }

   public void btn_first( )
   {
      nKeyPressed = (byte)(2) ;
      IsConfirmed = 0 ;
      scanstart_0o24( ) ;
      if ( ( RcdFound24 == 0 ) )
      {
         context.msgStatus( localUtil.getMessages().getMessage("norectobrow") );
      }
      else
      {
         Gx_mode = "UPD" ;
         setNextFocus( edtDESDOCSUN );
      }
      scanend_0o24( ) ;
      geteq( ) ;
      if ( ( sanomodError == 0 ) )
      {
         handleErrors();
      }
      setFocusNext();
   }

   public void btn_previous( )
   {
      nKeyPressed = (byte)(2) ;
      IsConfirmed = 0 ;
      move_previous( ) ;
      if ( ( RcdFound24 == 0 ) )
      {
         context.msgStatus( localUtil.getMessages().getMessage("norectobrow") );
      }
      else
      {
         Gx_mode = "UPD" ;
         setNextFocus( edtDESDOCSUN );
      }
      geteq( ) ;
      if ( ( sanomodError == 0 ) )
      {
         handleErrors();
      }
      setFocusNext();
   }

   public void btn_next( )
   {
      nKeyPressed = (byte)(2) ;
      IsConfirmed = 0 ;
      move_next( ) ;
      if ( ( RcdFound24 == 0 ) )
      {
         context.msgStatus( localUtil.getMessages().getMessage("norectobrow") );
      }
      else
      {
         Gx_mode = "UPD" ;
         setNextFocus( edtDESDOCSUN );
      }
      geteq( ) ;
      if ( ( sanomodError == 0 ) )
      {
         handleErrors();
      }
      setFocusNext();
   }

   public void btn_last( )
   {
      nKeyPressed = (byte)(2) ;
      IsConfirmed = 0 ;
      scanstart_0o24( ) ;
      if ( ( RcdFound24 == 0 ) )
      {
         context.msgStatus( localUtil.getMessages().getMessage("norectobrow") );
      }
      else
      {
         while ( ( RcdFound24 != 0 ) )
         {
            scannext_0o24( ) ;
         }
         Gx_mode = "UPD" ;
         setNextFocus( edtDESDOCSUN );
      }
      scanend_0o24( ) ;
      geteq( ) ;
      if ( ( sanomodError == 0 ) )
      {
         handleErrors();
      }
      setFocusNext();
   }

   public void btn_select( )
   {
      geteq_nomod( ) ;
   }

   public void chkps_0o24( )
   {
      if ( ( GXutil.strcmp(Gx_mode, "INS") != 0 ) )
      {
         /* Using cursor T00242 */
         pr_default.execute(0, new Object[] {new Byte(A355CODDOC)});
         if ( ! (pr_default.getStatus(0) != 103) )
         {
            pushError( localUtil.getMessages().getMessage("lock", new Object[] {"MMDCS10"}) );
            AnyError = (short)(1) ;
            keepFocus();
            return  ;
         }
         Gx_longc = false ;
         if ( (pr_default.getStatus(0) == 101) || ( GXutil.strcmp(Z356DESDOC, T00242_A356DESDOC[0]) != 0 ) )
         {
            pushError( localUtil.getMessages().getMessage("waschg", new Object[] {"MMDCS10"}) );
            AnyError = (short)(1) ;
            keepFocus();
            return  ;
         }
      }
   }

   public void insert_0o24( )
   {
      checket_0o24( ) ;
      if ( ( AnyError == 0 ) )
      {
         zm0o24( 0) ;
         chkps_0o24( ) ;
         if ( ( AnyError == 0 ) )
         {
            after_confirm_0o24( ) ;
            if ( ( AnyError == 0 ) )
            {
               /* Using cursor T00247 */
               pr_default.execute(5, new Object[] {new Byte(A355CODDOC), A356DESDOC});
               if ( (pr_default.getStatus(5) == 1) )
               {
                  pushError( localUtil.getMessages().getMessage("noupdate") );
                  AnyError = (short)(1) ;
                  keepFocus();
               }
               if ( ( AnyError == 0 ) )
               {
                  /* Start of After( Insert) rules */
                  /* End of After( Insert) rules */
                  if ( ( AnyError == 0 ) )
                  {
                     /* Save values for previous() function. */
                     context.msgStatus( localUtil.getMessages().getMessage("sucadded") );
                     reset_caption_0o0( ) ;
                  }
               }
               else
               {
                  pushError( localUtil.getMessages().getMessage("unexp") );
                  AnyError = (short)(1) ;
                  keepFocus();
               }
            }
         }
         else
         {
            ld0o24( ) ;
         }
         endlvl_0o24( ) ;
      }
      close_checket_0o24( ) ;
   }

   public void update_0o24( )
   {
      checket_0o24( ) ;
      if ( ( AnyError == 0 ) )
      {
         chkps_0o24( ) ;
         if ( ( AnyError == 0 ) )
         {
            after_confirm_0o24( ) ;
            if ( ( AnyError == 0 ) )
            {
               /* Using cursor T00248 */
               pr_default.execute(6, new Object[] {A356DESDOC, new Byte(A355CODDOC)});
               if ( ( AnyError == 0 ) )
               {
                  /* Start of After( update) rules */
                  /* End of After( update) rules */
                  if ( ( AnyError == 0 ) )
                  {
                     geteq( ) ;
                     context.msgStatus( localUtil.getMessages().getMessage("sucupdated") );
                     reset_caption_0o0( ) ;
                  }
               }
               else
               {
                  pushError( localUtil.getMessages().getMessage("unexp") );
                  AnyError = (short)(1) ;
                  keepFocus();
               }
            }
         }
         endlvl_0o24( ) ;
      }
      close_checket_0o24( ) ;
   }

   public void delete( )
   {
      Gx_mode = "DLT" ;
      chkps_0o24( ) ;
      if ( ( AnyError == 0 ) )
      {
         delete_controls0o24( ) ;
         /* No cascading delete specified. */
         after_confirm_0o24( ) ;
         if ( ( AnyError == 0 ) )
         {
            /* Using cursor T00249 */
            pr_default.execute(7, new Object[] {new Byte(A355CODDOC)});
            if ( ( AnyError == 0 ) )
            {
               /* Start of After( delete) rules */
               /* End of After( delete) rules */
               if ( ( AnyError == 0 ) )
               {
                  move_next( ) ;
                  if ( ( RcdFound24 == 0 ) )
                  {
                     init_all0o24( ) ;
                     Gx_mode = "INS" ;
                  }
                  else
                  {
                     geteq( ) ;
                     Gx_mode = "UPD" ;
                  }
                  context.msgStatus( localUtil.getMessages().getMessage("sucdeleted") );
                  reset_caption_0o0( ) ;
               }
            }
            else
            {
               pushError( localUtil.getMessages().getMessage("unexp") );
               AnyError = (short)(1) ;
               keepFocus();
            }
         }
      }
      sMode24 = Gx_mode ;
      Gx_mode = "DLT" ;
      endlvl_0o24( ) ;
      Gx_mode = sMode24 ;
   }

   public void delete_controls0o24( )
   {
      samod( ) ;
      /* No delete mode formulas found. */
      /* The base table is not referenced outside the transaction. */
   }

   public void endlvl_0o24( )
   {
      if ( ( GXutil.strcmp(Gx_mode, "INS") != 0 ) )
      {
         pr_default.close(0);
      }
      if ( ( AnyError == 0 ) && ( sanomodError == 0 ) )
      {
         Application.commit(context, remoteHandle, "DEFAULT", "tdocumentos");
         /* After transaction rules */
         /* Execute 'After Trn' event if defined. */
         trnEnded = 1 ;
      }
      else
      {
         Application.rollback(context, remoteHandle, "DEFAULT", "tdocumentos");
      }
   }

   public void scanstart_0o24( )
   {
      /* Using cursor T002410 */
      pr_default.execute(8);
      RcdFound24 = 0 ;
      if ( (pr_default.getStatus(8) != 101) )
      {
         RcdFound24 = (short)(1) ;
         A355CODDOC = T002410_A355CODDOC[0] ;
      }
   }

   public void scannext_0o24( )
   {
      pr_default.readNext(8);
      RcdFound24 = 0 ;
      if ( (pr_default.getStatus(8) != 101) )
      {
         RcdFound24 = (short)(1) ;
         A355CODDOC = T002410_A355CODDOC[0] ;
      }
   }

   public void scanend_0o24( )
   {
      pr_default.close(8);
   }

   public void after_confirm_0o24( )
   {
      /* After confirm rules */
   }

   public void confirm_0o0( )
   {
      if ( ( GXutil.strcmp(Gx_mode, "DLT") == 0 ) )
      {
         delete_controls0o24( ) ;
      }
      else
      {
         checket_0o24( ) ;
         close_checket_0o24( ) ;
      }
      if ( ( AnyError == 0 ) && ( sanomodError == 0 ) )
      {
         PreviousCaption = bttBtn_enter.getCaption() ;
         PreviousTooltip = bttBtn_enter.getTooltip() ;
         IsConfirmed = (short)(1) ;
      }
   }

   protected void cleanup( )
   {
      if (cleanedUp) {
         return  ;
      }
      if (!exitExecuted) {
         exitExecuted = true;
         GXExit();
      }
      super.cleanup();
      Application.cleanup(context, this, remoteHandle);
   }

   public void initialize( )
   {
      IsConfirmed = 0 ;
      trnEnded = 0 ;
      nKeyPressed = 0 ;
      PreviousTooltip = "" ;
      PreviousCaption = "" ;
      A356DESDOC = "" ;
      A355CODDOC = 0 ;
      K355CODDOC = 0 ;
      lastAnyError = 0 ;
      Z356DESDOC = "" ;
      Gx_longc = false ;
      GX_JID = 0 ;
      Gx_BScreen = 0 ;
      RcdFound24 = 0 ;
      T00244_A355CODDOC = new byte[1] ;
      T00243_A355CODDOC = new byte[1] ;
      T00243_A356DESDOC = new String[] {""} ;
      Z355CODDOC = 0 ;
      sMode24 = "" ;
      T00245_A355CODDOC = new byte[1] ;
      T00246_A355CODDOC = new byte[1] ;
      T00242_A355CODDOC = new byte[1] ;
      T00242_A356DESDOC = new String[] {""} ;
      T002410_A355CODDOC = new byte[1] ;
      pr_default = new DataStoreProvider(context, remoteHandle, new tdocumentos__default(),
         new Object[] {
             new Object[] {
            T00242_A355CODDOC, T00242_A356DESDOC
            }
            , new Object[] {
            T00243_A355CODDOC, T00243_A356DESDOC
            }
            , new Object[] {
            T00244_A355CODDOC
            }
            , new Object[] {
            T00245_A355CODDOC
            }
            , new Object[] {
            T00246_A355CODDOC
            }
            , new Object[] {
            }
            , new Object[] {
            }
            , new Object[] {
            }
            , new Object[] {
            T002410_A355CODDOC
            }
         }
      );
      reloadDynamicLists(0);
   }

   protected byte geteqAfterKey= 1 ;
   protected byte nKeyPressed ;
   protected byte A355CODDOC ;
   protected byte K355CODDOC ;
   protected byte Gx_BScreen ;
   protected byte Z355CODDOC ;
   protected short IsConfirmed ;
   protected short RcdFound24 ;
   protected int trnEnded ;
   protected int lastAnyError ;
   protected int GX_JID ;
   protected String PreviousTooltip ;
   protected String PreviousCaption ;
   protected String A356DESDOC ;
   protected String Z356DESDOC ;
   protected String sMode24 ;
   protected boolean Gx_longc ;
   protected GXPanel GXPanel1 ;
   protected GUIObjectByte edtCODDOCSUN ;
   protected GUIObjectString edtDESDOCSUN ;
   protected IGXButton bttBtn_first ;
   protected IGXButton bttBtn_previous ;
   protected IGXButton bttBtn_next ;
   protected IGXButton bttBtn_last ;
   protected IGXButton bttBtn_select ;
   protected IGXButton bttBtn_enter ;
   protected IGXButton bttBtn_cancel ;
   protected IGXButton bttBtn_delete ;
   protected IGXButton bttBtn_help ;
   protected ILabel lbllbl12 ;
   protected ILabel lbllbl14 ;
   protected IDataStoreProvider pr_default ;
   protected byte[] T00244_A355CODDOC ;
   protected byte[] T00243_A355CODDOC ;
   protected String[] T00243_A356DESDOC ;
   protected byte[] T00245_A355CODDOC ;
   protected byte[] T00246_A355CODDOC ;
   protected byte[] T00242_A355CODDOC ;
   protected String[] T00242_A356DESDOC ;
   protected byte[] T002410_A355CODDOC ;
}

final class tdocumentos__default extends DataStoreHelperBase implements ILocalDataStoreHelper
{
   public Cursor[] getCursors( )
   {
      return new Cursor[] {
          new ForEachCursor("T00242", "SELECT [CODDOCSUN], [DESDOCSUN] FROM [MMDCS10] WITH (UPDLOCK) WHERE [CODDOCSUN] = ? ",true, GX_NOMASK, false, this,0,false )
         ,new ForEachCursor("T00243", "SELECT [CODDOCSUN], [DESDOCSUN] FROM [MMDCS10] WITH (NOLOCK) WHERE [CODDOCSUN] = ? ",true, GX_NOMASK, false, this,0,false )
         ,new ForEachCursor("T00244", "SELECT [CODDOCSUN] FROM [MMDCS10] WITH (FASTFIRSTROW NOLOCK) WHERE [CODDOCSUN] = ? ",true, GX_NOMASK, false, this,0,false )
         ,new ForEachCursor("T00245", "SELECT [CODDOCSUN] FROM [MMDCS10] WITH (FASTFIRSTROW NOLOCK) WHERE ( [CODDOCSUN] > ?) ORDER BY [CODDOCSUN] ",true, GX_NOMASK, false, this,0,false )
         ,new ForEachCursor("T00246", "SELECT [CODDOCSUN] FROM [MMDCS10] WITH (FASTFIRSTROW NOLOCK) WHERE ( [CODDOCSUN] < ?) ORDER BY [CODDOCSUN] DESC ",true, GX_NOMASK, false, this,0,false )
         ,new UpdateCursor("T00247", "INSERT INTO [MMDCS10] ([CODDOCSUN], [DESDOCSUN]) VALUES (?, ?)", GX_NOMASK)
         ,new UpdateCursor("T00248", "UPDATE [MMDCS10] SET [DESDOCSUN]=?  WHERE [CODDOCSUN] = ?", GX_NOMASK)
         ,new UpdateCursor("T00249", "DELETE FROM [MMDCS10]  WHERE [CODDOCSUN] = ?", GX_NOMASK)
         ,new ForEachCursor("T002410", "SELECT [CODDOCSUN] FROM [MMDCS10] WITH (FASTFIRSTROW NOLOCK) ORDER BY [CODDOCSUN] ",true, GX_NOMASK, false, this,0,false )
      };
   }

   public void getResults( int cursor ,
                           IFieldGetter rslt ,
                           Object[] buf ) throws SQLException
   {
      switch ( cursor )
      {
            case 0 :
               ((byte[]) buf[0])[0] = rslt.getByte(1) ;
               ((String[]) buf[1])[0] = rslt.getString(2, 50) ;
               break;
            case 1 :
               ((byte[]) buf[0])[0] = rslt.getByte(1) ;
               ((String[]) buf[1])[0] = rslt.getString(2, 50) ;
               break;
            case 2 :
               ((byte[]) buf[0])[0] = rslt.getByte(1) ;
               break;
            case 3 :
               ((byte[]) buf[0])[0] = rslt.getByte(1) ;
               break;
            case 4 :
               ((byte[]) buf[0])[0] = rslt.getByte(1) ;
               break;
            case 8 :
               ((byte[]) buf[0])[0] = rslt.getByte(1) ;
               break;
      }
   }

   public void setParameters( int cursor ,
                              IFieldSetter stmt ,
                              Object[] parms ) throws SQLException
   {
      switch ( cursor )
      {
            case 0 :
               stmt.setByte(1, ((Byte) parms[0]).byteValue());
               break;
            case 1 :
               stmt.setByte(1, ((Byte) parms[0]).byteValue());
               break;
            case 2 :
               stmt.setByte(1, ((Byte) parms[0]).byteValue());
               break;
            case 3 :
               stmt.setByte(1, ((Byte) parms[0]).byteValue());
               break;
            case 4 :
               stmt.setByte(1, ((Byte) parms[0]).byteValue());
               break;
            case 5 :
               stmt.setByte(1, ((Byte) parms[0]).byteValue());
               stmt.setString(2, (String)parms[1], 50);
               break;
            case 6 :
               stmt.setString(1, (String)parms[0], 50);
               stmt.setByte(2, ((Byte) parms[1]).byteValue());
               break;
            case 7 :
               stmt.setByte(1, ((Byte) parms[0]).byteValue());
               break;
      }
   }

}

